package game.engine.base

import java.util.*

abstract class Pool<T>{

    private val mCache = LinkedList<T>()

    abstract fun create():T

    fun get(): T {
        return if (mCache.size < 1) {
            create()
        } else {
            mCache.poll()
        }
    }

    fun free(t: T) {
        if (CoreDebug.PoolDebug) {
            if (mCache.contains(t)) {
                CoreDebug.warn("t:$t already in cache!")
                return
            }
        }
        mCache.add(t)
    }
}